<template>
  <el-table :data="tableData" border style="width: 100%" :summary-method="getSummaries" show-summary>
    <el-table-column type="index" label="序号" width="60" align="center" show-overflow-tooltip></el-table-column>
    <!-- <el-table-column v-if="eventType=='level'" label="事件类型" prop="level" align="center"></el-table-column>
    <el-table-column v-if="eventType=='problem_type'" label="问题类型" prop="problemType" align="center"></el-table-column>
    <el-table-column v-if="eventType=='detail_type'" label="详细类型" prop="detailType" align="center"></el-table-column> -->
    <el-table-column label="类型名称" prop="name" align="center"></el-table-column>
    <el-table-column label="总工单（张）" prop="cnt" align="center"></el-table-column>
    <el-table-column label="已完成（张）" prop="finished" align="center"></el-table-column>
    <el-table-column label="已过期（张）" prop="expired" align="center"></el-table-column>
    <el-table-column label="已审核（张）" prop="audit" align="center"></el-table-column>
    <!-- <el-table-column label="已完成未过期" prop="finishedNotExpired" align="center"></el-table-column> -->
    <el-table-column label="及时完工率（%）" prop="timelyRate" align="center"></el-table-column>
    <el-table-column label="完工率（%）" prop="completionRate" align="center"></el-table-column>
    <el-table-column label="合格率（%）" prop="passRate" align="center"></el-table-column>
    <!-- <el-table-column label="操作" prop="name" align="center">
      <template slot-scope="{row}">
        <el-button type="text" @click="detail(row)">详情</el-button>
      </template>
    </el-table-column> -->
  </el-table>
</template>
<script>
export default {
  props: {
    tableData: {
      type: Array,
      default: () => []
    },
    eventType: {
      type: String,
      default: 'category'
    }
  },
  watch: {},
  methods: {
    detail(row) {
      if(!row.problemId) return;
      this.$store.dispatch('TopbarChange', "eventCenterLayout");
      this.$router.push({
        path: '/patrolEvent',
        query: {
          level: row.problemId
        }
      })
      this.$emit('')
    },
    getSummaries(param) {
      const { columns, data } = param
      const sums = []
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = '总计'
          return
        }

        // console.log(column.property)
        if(['level', 'problemType','detailType'].includes(column.property)) {
          sums[index] = 'N/A'
          return;
        }

        const item = data[0]
        // console.log("item", item)
        if(item && 'timelyRate' == column.property) {
          sums[index] = item['totalTimelyRate']&&item['totalTimelyRate'].toFixed(1)
          return;
        }
        if(item && 'completionRate' == column.property) {
          sums[index] = item['totalCompletionRate']&&item['totalCompletionRate'].toFixed(1)
          return;
        }
        if(item && 'passRate' == column.property) {
          sums[index] = item['totalPassRate']&&item['totalPassRate'].toFixed(1)
          return;
        }
        const values = data.map(item => Number(item[column.property]))
        // console.log('values---',values)
        if (!values.every(value => isNaN(value))) {
          sums[index] = values.reduce((prev, curr) => {
            const value = Number(curr)
            if (!isNaN(value)) {
              return prev + curr
            } else {
              return prev
            }
          }, 0)
          // sums[index] += ' 元'
        } else {
          sums[index] = 'N/A'
        }
      })

      return sums
    }
  }
}
</script>
